{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4759697370548336\n",
      "{'C': 1, 'penalty': 'l1'}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nO3dd3iUVdrH8e89M+mElkaVJr0XAZUiFkSlSlWQoojsCwquoq669gJrX8UFRFBBBRSRKiAqoigdQhEEREpCSagB0jPn/WMGCDDApAxPJrk/e82VmWfOmfwedXPPU845YoxBKaWUupDN6gBKKaUKJi0QSimlPNICoZRSyiMtEEoppTzSAqGUUsojh9UB8lNkZKSpXLmy1TGUUspvrF279rAxJsrTe4WqQFSuXJk1a9ZYHUMppfyGiOy51Hs+PcUkIh1E5E8R2SkiT3l4f5SIbHA/NotIloiU9qavUkop3/JZgRAROzAWuAOoA9wjInWytzHGvGGMaWSMaQT8C/jZGHPUm75KKaV8y5dHEM2BncaYXcaYdGAa0OUy7e8BvsxlX6WUUvnMl9cgygP7sr2OA1p4aigioUAHYHgu+g4BhgBcc801eUuslPJbGRkZxMXFkZqaanWUAik4OJgKFSoQEBDgdR9fFgjxsO1SEz91ApYbY47mtK8xZgIwAaBZs2Y6sZRSRVRcXBzh4eFUrlwZEU9/QoouYwxHjhwhLi6OKlWqeN3Pl6eY4oCK2V5XAPZfom0fzp1eymlfpZQiNTWViIgILQ4eiAgRERE5PrryZYFYDVQXkSoiEoirCMy5sJGIlADaArNz2lcppbLT4nBpufln47MCYYzJxHVNYRGwFZhhjNkiIkNFZGi2pt2AxcaY01fq66usv09+kp0bf/PVxyulCqje43+n9/jfrY5RYPl0HIQxZo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Iw56J6v/yf360tdnD7zGd8A//Lj9bhVIaB3MSmV/+a5F3EJBF52H1lgjEkRkedxrUu991Kd3YsLfavFQVlNjyCUUkp5pNcglFJKeaQFQimllEdaIJRSSnmkBUIppZRHWiCUUkp59P8V3ZjwpVjAegAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#首先 import 必要的模块\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "# 数据标准化已经在\"FE_pima-indians-diabetes.csv\"完成\n",
    "# 通过LogisticRegression + GridSearchCV进行超参数调优,neg_log_loss  5折\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "#train.head()\n",
    "\n",
    "y_train = train['Target']\n",
    "X_train = train.drop(\"Target\", axis=1)\n",
    "feat_names = X_train.columns\n",
    "#print(feat_names)\n",
    "\n",
    "penaltys = ['l1','l2']\n",
    "Cs = [ 0.001, 0.01, 0.1, 1, 10, 100, 1000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "lr_penalty= LogisticRegression(solver='liblinear')\n",
    "# 设置return_train_score为True，否则输出结果中不包含训练数据\n",
    "grid= GridSearchCV(lr_penalty, tuned_parameters,cv=5, scoring='neg_log_loss',n_jobs = 4,return_train_score='True')\n",
    "grid.fit(X_train,y_train)\n",
    "\n",
    "# 查看最好模型参数及评价分数\n",
    "print(-grid.best_score_)\n",
    "print(grid.best_params_)\n",
    "\n",
    "#print(grid.cv_results_)\n",
    "# plot CV误差曲线\n",
    "test_means = grid.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = grid.cv_results_[ 'std_test_score' ]\n",
    "train_means = grid.cv_results_[ 'mean_train_score' ]\n",
    "train_stds = grid.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'logloss' )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.7747644512350395\n",
      "{'C': 0.1, 'penalty': 'l2'}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nO3deXhU5fn/8fedSUIIYQkhbAlLEBDZwhIJKOKGEqkbKIKKWPr1p1ix1rYo1bpbN2qrbW1RUcC64F4tIuCOokAAWcKOYQs7SSCQhWQy9++PGTCEASbJDCfL/bquXMw58zxn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4F7fENK7+N9DkQG3udoLwQO+Pp8wrEF4xagJbBRRFYCL/Pz8yIuBGrc7KKmdrHZXI0JMhGJ8T1EPg7vUcW5qrrLN1//V77lE52cPrKND4A/1uDncZtawK5iMib4Zvoe4hIJPOY7skBVC0XkIbzPpd56os6+hwv914qDcZodQRhjjPHLzkEYY4zxywqEMcYYv6xAGGOM8csKhDHGGL+sQBhjjPHLCoQxxhi//j/QNAG9MZuTmAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#首先 import 必要的模块\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "# 数据标准化已经在\"FE_pima-indians-diabetes.csv\"完成\n",
    "# 通过LogisticRegression + GridSearchCV进行超参数调优,accuracy  5折\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "#train.head()\n",
    "\n",
    "y_train = train['Target']\n",
    "X_train = train.drop(\"Target\", axis=1)\n",
    "feat_names = X_train.columns\n",
    "#print(feat_names)\n",
    "\n",
    "penaltys = ['l1','l2']\n",
    "Cs = [ 0.001, 0.01, 0.1, 1, 10, 100, 1000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "lr_penalty= LogisticRegression(solver='liblinear')\n",
    "# 设置return_train_score为True，否则输出结果中不包含训练数据\n",
    "grid= GridSearchCV(lr_penalty, tuned_parameters,cv=5, scoring='accuracy',n_jobs = 4,return_train_score='True')\n",
    "grid.fit(X_train,y_train)\n",
    "\n",
    "# 查看最好模型参数及评价分数\n",
    "print(-grid.best_score_)\n",
    "print(grid.best_params_)\n",
    "\n",
    "#print(grid.cv_results_)\n",
    "# plot CV误差曲线\n",
    "test_means = -grid.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = -grid.cv_results_[ 'std_test_score' ]\n",
    "train_means = -grid.cv_results_[ 'mean_train_score' ]\n",
    "train_stds = -grid.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'logloss' )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cs : 0.001 0.01 0.1 1 10 100 1000\n",
      "scores : -0.6931471805599453 -0.6359675905837048 -0.47851890402711844 -0.47596993163439116 -0.476405052347925\n"
     ]
    }
   ],
   "source": [
    "#首先 import 必要的模块\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "from sklearn.linear_model import LogisticRegressionCV\n",
    "\n",
    "# 数据标准化已经在\"FE_pima-indians-diabetes.csv\"完成\n",
    "# LogisticRegressionCV进行超参数调优,accuracy  5折\n",
    "%matplotlib inline\n",
    "\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "#train.head()\n",
    "\n",
    "y_train = train['Target']\n",
    "X_train = train.drop(\"Target\", axis=1)\n",
    "feat_names = X_train.columns\n",
    "#print(feat_names)\n",
    "\n",
    "# 通过LogisticRegressionCV进行超参数调优,neg_log_loss  5折\n",
    "lrcv_penalty= LogisticRegressionCV(Cs = [ 0.001, 0.01, 0.1, 1, 10, 100, 1000],penalty = 'l1',solver='liblinear',cv=5,scoring='neg_log_loss',n_jobs = 4)\n",
    "lrcv_penalty.fit(X_train,y_train)\n",
    "\n",
    "mean_scores = np.mean(lrcv_penalty.scores_[1],axis = 0)\n",
    "\n",
    "print(\"Cs : {} {} {} {} {} {} {}\".format(0.001, 0.01, 0.1, 1, 10,100,1000))\n",
    "print(\"scores : {} {} {} {} {}\".format(mean_scores[0], mean_scores[1],mean_scores[2],mean_scores[3],mean_scores[4],mean_scores[5],mean_scores[6]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cs : 0.001 0.01 0.1 1 10 100 1000\n",
      "scores : 0.7474492827434004 0.7617859264918089 0.7747644512350395 0.7708683473389355 0.7708683473389355\n"
     ]
    }
   ],
   "source": [
    "#首先 import 必要的模块\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "from sklearn.linear_model import LogisticRegressionCV\n",
    "\n",
    "# 数据标准化已经在\"FE_pima-indians-diabetes.csv\"完成\n",
    "# LogisticRegressionCV进行超参数调优,accuracy  5折\n",
    "%matplotlib inline\n",
    "\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "#train.head()\n",
    "\n",
    "y_train = train['Target']\n",
    "X_train = train.drop(\"Target\", axis=1)\n",
    "feat_names = X_train.columns\n",
    "#print(feat_names)\n",
    "\n",
    "# 通过LogisticRegressionCV进行超参数调优,neg_log_loss  5折\n",
    "lrcv_penalty= LogisticRegressionCV(Cs = [ 0.001, 0.01, 0.1, 1, 10,100,1000], penalty='l2',solver='liblinear',cv=5,scoring='accuracy',n_jobs = 4)\n",
    "lrcv_penalty.fit(X_train,y_train)\n",
    "mean_scores = np.mean(lrcv_penalty.scores_[1],axis = 0)\n",
    "\n",
    "print(\"Cs : {} {} {} {} {} {} {}\".format(0.001, 0.01, 0.1, 1, 10,100,1000))\n",
    "print(\"scores : {} {} {} {} {}\".format(mean_scores[0], mean_scores[1],mean_scores[2],mean_scores[3],mean_scores[4],mean_scores[5],mean_scores[6]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['accuracy',\n",
       " 'adjusted_mutual_info_score',\n",
       " 'adjusted_rand_score',\n",
       " 'average_precision',\n",
       " 'balanced_accuracy',\n",
       " 'completeness_score',\n",
       " 'explained_variance',\n",
       " 'f1',\n",
       " 'f1_macro',\n",
       " 'f1_micro',\n",
       " 'f1_samples',\n",
       " 'f1_weighted',\n",
       " 'fowlkes_mallows_score',\n",
       " 'homogeneity_score',\n",
       " 'jaccard',\n",
       " 'jaccard_macro',\n",
       " 'jaccard_micro',\n",
       " 'jaccard_samples',\n",
       " 'jaccard_weighted',\n",
       " 'max_error',\n",
       " 'mutual_info_score',\n",
       " 'neg_brier_score',\n",
       " 'neg_log_loss',\n",
       " 'neg_mean_absolute_error',\n",
       " 'neg_mean_gamma_deviance',\n",
       " 'neg_mean_poisson_deviance',\n",
       " 'neg_mean_squared_error',\n",
       " 'neg_mean_squared_log_error',\n",
       " 'neg_median_absolute_error',\n",
       " 'neg_root_mean_squared_error',\n",
       " 'normalized_mutual_info_score',\n",
       " 'precision',\n",
       " 'precision_macro',\n",
       " 'precision_micro',\n",
       " 'precision_samples',\n",
       " 'precision_weighted',\n",
       " 'r2',\n",
       " 'recall',\n",
       " 'recall_macro',\n",
       " 'recall_micro',\n",
       " 'recall_samples',\n",
       " 'recall_weighted',\n",
       " 'roc_auc',\n",
       " 'roc_auc_ovo',\n",
       " 'roc_auc_ovo_weighted',\n",
       " 'roc_auc_ovr',\n",
       " 'roc_auc_ovr_weighted',\n",
       " 'v_measure_score']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sklearn\n",
    "\n",
    "#查看sklearn支持的scoring\n",
    "sorted(sklearn.metrics.SCORERS.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
